<template>
	<view>
		<z-paging ref="paging" v-model="dataList" @query="queryList">
			<!-- 需要固定在顶部不滚动的view放在slot="top"的view中，如果需要跟着滚动，则不要设置slot="top" -->
			<!-- 注意！此处的z-tabs为独立的组件，可替换为第三方的tabs，若需要使用z-tabs，请在插件市场搜索z-tabs并引入，否则会报插件找不到的错误 -->
			<template #top>
				<view class="p30">
					<view class="mb20">
						您好, {{ staffName || '' }}:
					</view>
					<view class="mb20">
						您此月生产数量 {{ produceNumber || 0 }}
					</view>
					<view class="mb20">
						总工费: ￥{{ totalAmount || 0 }}
					</view>
					<view class="mb20">
						历史订单信息:
					</view>
					<view class="flex">
						<view class="input_moon" @click="show=true">
							{{ monthNumber }}
						</view>
						<view class="btn" @click="handleQuery">
							查询
						</view>
					</view>
				</view>
			</template>


			<view class="p30 content">
				<view class="flex item">
					<view class="bold" style="flex: 2;">
						订单名称
					</view>
					<view class="bold" style="flex: 1;">
						生产数量
					</view>
					<view class="bold" style="flex: 1;">
						总工费
					</view>
				</view>
				<view class="flex item" v-for="(item, index) in dataList" :key="index">
					<view class="" style="flex: 2; text-align: center;">
						{{ item.productName }}
					</view>
					<view class="" style="flex: 1; text-align: center;">
						{{ item.number }}
					</view>
					<view class="" style="flex: 1; text-align: center;">
						<span v-if="totalAmount">
							￥{{ item.totalAmount }}
						</span>
					</view>
				</view>
			</view>
		</z-paging>


		<u-picker :show="show" :columns="columns" @close="show=false" @confirm="handleConfirm"></u-picker>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dataList: [],
				monthNumber: '',
				show: false,
				columns: [
					[1,2,3,4,5,6,7,8,9,10,11,12]
				],
				staffName: '',
				totalAmount: '',
				produceNumber: ''
			};
		},
		onLoad() {
			const monthNumber = new Date().getMonth() + 1;
			this.monthNumber = monthNumber
		},
		methods: {
			handleQuery() {
				this.$refs.paging.reload();
			},
			queryList(pageNo, pageSize) {
				//组件加载时会自动触发此方法，因此默认页面加载时会自动触发，无需手动调用
				//这里的pageNo和pageSize会自动计算好，直接传给服务器即可
				//模拟请求服务器获取分页数据，请替换成自己的网络请求
				const formData = {
					month: this.monthNumber,
				}

				// this.$refs.paging.complete([1, 2, 3, 4, 5, 6]);

				this.$api.getMyOrderApi(formData).then(res => {
					//将请求的结果数组传递给z-paging
					this.staffName = res.data.staffName
					this.totalAmount = res.data.totalAmount
					this.produceNumber = res.data.produceNumber
					this.$refs.paging.complete(res.data.details);
				}).catch(res => {
					console.log(res)
					//如果请求失败写this.$refs.paging.complete(false);
					//注意，每次都需要在catch中写这句话很麻烦，z-paging提供了方案可以全局统一处理
					//在底层的网络请求抛出异常时，写uni.$emit('z-paging-error-emit');即可
					this.$refs.paging.complete(false);
				})
			},
			
			
			handleConfirm({value}) {
				this.monthNumber = value[0]
				this.show = false
			}
		}
	}
</script>

<style lang="scss" scoped>
	.input_moon {
		width: 400rpx;
		height: 50rpx;
		background-color: #FFF;
		border-radius: 10rpx;
		border: 1rpx solid #BFBFBF;
		margin-right: 12rpx;
		padding-left: 30rpx;
	}

	.btn {
		height: 50rpx;
		width: 120rpx;
		text-align: center;
		line-height: 50rpx;
		background-color: #EAF5FF;
		color: #92C5F5;
		border-radius: 10rpx;
		border: 1rpx solid #92C5F5;
	}

	.content {
		background-color: #FFF;
	}

	.bold {
		font-weight: bold;
		text-align: center;
	}

	.item {
		height: 65rpx;
		line-height: 65rpx;
		border-bottom: 1rpx solid #BBBBBB;
	}
</style>